package cn.tx.controller;

import cn.tx.constant.MessageConstant;
import cn.tx.entity.Result;
import cn.tx.pojo.Member;
import cn.tx.pojo.Order;
import cn.tx.service.OrderService;
import cn.tx.utils.DateUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/9/5 22:43
 * @Email: 1164763541@qq.com
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Reference
    private OrderService orderService;

    @RequestMapping("save.do")
    public Result save(@RequestBody Map map) {
        try {
            //数据预处理

            String idCard = (String) map.get("idCard");//身份证号
            String name = (String) map.get("name");//名字
            Date date = DateUtils.parseString2Date((String) map.get("orderDate"));//体检时间

            Integer setmealId =Integer.parseInt(map.get("setmealId").toString());//套餐id
            String sex = (String) map.get("sex");//性别
            String telephone = (String) map.get("telephone");//手机号
            String validateCode = (String) map.get("validateCode");//验证码
            //封装数据

            Order order = new Order();
            order.setOrderDate(date);
            order.setOrderType(Order.ORDERTYPE_WEIXIN);
            order.setOrderStatus(Order.ORDERSTATUS_NO);
            order.setSetmealId(setmealId);

            Member member = new Member();
            member.setSex(sex);
            member.setIdCard(idCard);
            member.setName(name);
            member.setPhoneNumber(telephone);
            orderService.save(order, member, validateCode);
            return new Result(true, MessageConstant.ORDER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDER_FULL);
        }
    }
    //保存数据


}
